import { trim, trimEnd } from 'lodash';
import { ConfigCenterSingleton } from '@libs/common/config-center/config-center.singleton';

function getBuildResourceFunc(basicPath: string) {
    return function buildResourceFunc(resourcePath: string) {
        return buildResource(resourcePath, basicPath);
    };
}

function buildResource(resourcePath: string, basicPath: string = '') {
    const host = ConfigCenterSingleton.siteConfig?.staticPath;

    return `${trimEnd(host, '/')}/assets/${trim(basicPath, '/')}/${trim(resourcePath, '/')}`;
}

export { buildResource, getBuildResourceFunc };
